﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SmartMathLibrary.Simulation.LogicalGate
{
    /// <summary>
    /// This class represents a two input channel gate control.
    /// </summary>
    [Serializable]
    public class TwoInputGateModule : AbstractInputGateModule
    {
        /// <summary>
        /// This field holds the specified gate function.
        /// </summary>
        private TwoInputGate inputgate;

        /// <summary>
        /// This function pointer fetches the input information for input channel A. 
        /// </summary>
        private ByteGrabber byteGrabberInputA;

        /// <summary>
        /// This function pointer fetches the input information for input channel B. 
        /// </summary>
        private ByteGrabber byteGrabberInputB;

        /// <summary>
        /// Initializes a new instance of the <see cref="TwoInputGateModule"/> class.
        /// </summary>
        /// <param name="inputgate">The specified gate function.</param>
        /// <param name="byteGrabberInputA">This function pointer fetches the input information for input channel A.</param>
        /// <param name="byteGrabberInputB">This function pointer fetches the input information for input channel B.</param>
        public TwoInputGateModule(TwoInputGate inputgate, ByteGrabber byteGrabberInputA, ByteGrabber byteGrabberInputB)
        {
            this.inputgate = inputgate;
            this.byteGrabberInputA = byteGrabberInputA;
            this.byteGrabberInputB = byteGrabberInputB;
        }

        /// <summary>
        /// Gets or sets the specified gate function.
        /// </summary>
        /// <value>The specified gate function.</value>
        public TwoInputGate Inputgate
        {
            get { return inputgate; }
            set { inputgate = value; }
        }

        /// <summary>
        /// Gets or sets the function pointer fetches the input information for input channel A.
        /// </summary>
        /// <value>The function pointer fetches the input information for input channel A.</value>
        public ByteGrabber ByteGrabberInputA
        {
            get { return byteGrabberInputA; }
            set { byteGrabberInputA = value; }
        }

        /// <summary>
        /// Gets or sets the function pointer fetches the input information for input channel B.
        /// </summary>
        /// <value>The function pointer fetches the input information for input channel B.</value>
        public ByteGrabber ByteGrabberInputB
        {
            get { return byteGrabberInputB; }
            set { byteGrabberInputB = value; }
        }

        /// <summary>
        /// Gets the logical result, which is defined by the gate and the specified input values.
        /// </summary>
        /// <returns>The result of the logical gate.</returns>
        public override Byte GetResult()
        {
            this.inputgate.A = this.byteGrabberInputA();
            this.inputgate.B = this.byteGrabberInputB();

            return this.inputgate.GetResult();
        }
    }
}